/**
 * 
 */
package com.antilia.infomaresme.provider;

import java.util.Iterator;

import org.apache.wicket.extensions.markup.html.repeater.data.table.ISortableDataProvider;
import org.apache.wicket.extensions.markup.html.repeater.util.SortableDataProvider;
import org.apache.wicket.model.IModel;

import com.antilia.infomaresme.InfomaresmeApplication;
import com.antilia.infomaresme.data.dao.interfaces.IItemNewsDao;
import com.antilia.infomaresme.data.dataobjects.Item;
import com.antilia.infomaresme.data.dataobjects.ItemNews;
import com.antilia.infomaresme.data.dataobjects.VisibilityStatus;

/**
 * @author Ernesto
 *
 */
public abstract class ItemNewssDataProvider extends SortableDataProvider<ItemNews>  implements ISortableDataProvider<ItemNews> {

	private static final long serialVersionUID = 1L;
		
	/**
	 * 
	 */
	public ItemNewssDataProvider() {
		
	}

	/* (non-Javadoc)
	 * @see org.apache.wicket.model.IDetachable#detach()
	 */
	public void detach() {

	}

	/* (non-Javadoc)
	 * @see org.apache.wicket.markup.repeater.data.IDataProvider#iterator(int, int)
	 */
	public Iterator<? extends ItemNews> iterator(int first, int count) {
		//boolean isAscending = (getSort() != null && getSort().getProperty()==null) || (getSort() != null && getSort().isAscending());
		return getIItemNewsDao().getNews(getItem(), getStatus(),  first, count).iterator();
	}

	/* (non-Javadoc)
	 * @see org.apache.wicket.markup.repeater.data.IDataProvider#size()
	 */
	public int size() {
		return getIItemNewsDao().countNews(getItem(), getStatus()).intValue();
	}

	/* (non-Javadoc)
	 * @see org.apache.wicket.markup.repeater.data.IDataProvider#model(java.lang.Object)
	 */
	public IModel<ItemNews> model(ItemNews object) {
		return new ItemNewsLdm(object);
	}

	protected final IItemNewsDao getIItemNewsDao() {
		return InfomaresmeApplication.getQAApplication().getiItemNewsDao();
	}
	
		
	protected abstract VisibilityStatus getStatus();
	
	public abstract Item getItem();
}
